#include "FloatingTask.h"

FloatingTask::FloatingTask(){
	title = CommonConstant::TASK_TITLE_UNTITLED;
	description = location = person = CommonConstant::EMPTY_STRING;
	priority = CommonConstant::TASK_INT_PRIORITY_MEDIUM;
	finishedStatus = CommonConstant::TASK_INT_STATUS_NOT_FINISHED;
	index = 0;
	taskType = CommonConstant::TASK_TYPE_FLOATING;
}

FloatingTask::FloatingTask(string newTitle, string newDescription, string newLocation, string newPerson,
						   int newPriority, int newFinishedStatus, int newIndex){
	title = newTitle;
	description = newDescription;
	location = newLocation;
	person = newPerson;
	priority = newPriority;
	finishedStatus = newFinishedStatus;
	index = newIndex;
	taskType = CommonConstant::TASK_TYPE_FLOATING;
}

FloatingTask* FloatingTask::clone() const{
	return new FloatingTask (*this);
}

string FloatingTask::getTitle(){ 
	return title; 
}

string FloatingTask::getDescription(){ 
	return description;
}

string FloatingTask::getLocation(){ 
	return location; 
}

string FloatingTask::getPerson(){
	return person; 
}

int FloatingTask::getPriority(){
	return priority;
}

int FloatingTask::getFinishedStatus(){
	return finishedStatus;
}

int FloatingTask::getIndex(){ 
	return index;
}

string FloatingTask::getStringPriority(){
	return determinePriority();
}

string FloatingTask::getStringFinishedStatus(){ 
	return determineFinishedStatus(); 
}

char FloatingTask::getTaskType(){ 
	return taskType; 
}

void FloatingTask::setTitle(string newTitle){ 
	title = newTitle;
}

void FloatingTask::setDescription(string newDescription){ 
	description = newDescription;
}

void FloatingTask::setLocation(string newLocation){ 
	location = newLocation;
}

void FloatingTask::setPerson(string newPerson){ 
	person = newPerson;
}

void FloatingTask::setPriority(int newPriority){ 
	priority = newPriority;
}

void FloatingTask::setPriority(string newPriority){
	priority = convertStringPriorityToInt(newPriority);
}

void FloatingTask::setFinishedStatus(int newFinishedStatus){
	finishedStatus = newFinishedStatus;
}

void FloatingTask::setFinishedStatus(string newFinishedStatus){
	finishedStatus = convertStringFinishedStatusToInt(newFinishedStatus);
}

void FloatingTask::setIndex(int newIndex){ 
	index = newIndex;
}

string FloatingTask::taskInfomation(){
	string text;

	for(int i=CommonConstant::INDEX_ZERO; i<CommonConstant::DISPLAY_PRIORITY_SIZE; i++){
		CommonConstant::stringPriority[i] = CommonConstant::WHITE_SPACE;
	}

	for(unsigned int i=CommonConstant::INDEX_ZERO;i<getStringPriority().size();i++){
		CommonConstant::stringPriority[i] = getStringPriority()[i];
	}
	int lastIndex = CommonConstant::DISPLAY_PRIORITY_SIZE - CommonConstant::INCREMENT;
	CommonConstant::stringPriority[lastIndex] = CommonConstant::NULL_CHARACTER;

	sprintf_s(CommonConstant::buffer,
			  CommonConstant::FLOATING_TASK_STRING_FORMAT.c_str(),
			  to_string(index).c_str(),
			  title.c_str(),
			  optionalInfomation().c_str(),
			  CommonConstant::stringPriority,
			  getStringFinishedStatus().c_str());

	return CommonConstant::buffer;
}

string FloatingTask::basicTaskInfomation(){
	string text;
	for(int i=CommonConstant::INDEX_ZERO; i<CommonConstant::DISPLAY_PRIORITY_SIZE; i++){
		CommonConstant::stringPriority[i] = CommonConstant::WHITE_SPACE;
	}

	for(unsigned int i=CommonConstant::INDEX_ZERO;i<getStringPriority().size();i++){
		CommonConstant::stringPriority[i] = getStringPriority()[i];
	}
	int lastIndex = CommonConstant::DISPLAY_PRIORITY_SIZE - CommonConstant::INCREMENT;
	CommonConstant::stringPriority[lastIndex] = CommonConstant::NULL_CHARACTER;

	sprintf_s(CommonConstant::buffer,
			  CommonConstant::FLOATING_TASK_STRING_FORMAT.c_str(),
			  to_string(index).c_str(),
			  title.c_str(),
			  CommonConstant::EMPTY_STRING.c_str(),
			  CommonConstant::stringPriority,
			  getStringFinishedStatus().c_str());

	return CommonConstant::buffer;
}

string FloatingTask::optionalInfomation(){
	string text;

	if(description != CommonConstant::EMPTY_STRING){
		text += "About: " + description + '\n';
	}

	if(location != CommonConstant::EMPTY_STRING){
		text += "At:    " + location + '\n';
	}

	if(person != CommonConstant::EMPTY_STRING) {
		text += "With:  " + person + '\n';
	}

	return text;
}

string FloatingTask::determinePriority(){
	switch (priority){
	case 0:
		return CommonConstant::TASK_STRING_PRIORITY_HIGH;
	case 1:
		return CommonConstant::TASK_STRING_PRIORITY_MEDIUM;
	case 2:
		return CommonConstant::TASK_STRING_PRIORITY_LOW;
	default:
		return CommonConstant::TASK_ATTRIBUTE_INVALID;
	}
}

string FloatingTask::determineFinishedStatus(){
	switch (finishedStatus){
	case 0:
		return CommonConstant::TASK_STRING_STATUS_NOT_FINISHED;
	case 1:
		return CommonConstant::TASK_STRING_STATUS_FINISHED;
	default:
		return CommonConstant::TASK_ATTRIBUTE_INVALID;
	}
}

string FloatingTask::toUpperCase(string word){
	for(unsigned int i=CommonConstant::INDEX_ZERO;i < word.size();i++){
		if(isalpha(word[i])){
			word[i] = toupper(word[i]);
		}
	}
	return word;
}

int FloatingTask::convertStringPriorityToInt(string stringPriority){
	if(isEqualIgnoreCaseString(stringPriority,CommonConstant::TASK_STRING_PRIORITY_HIGH)){
		return CommonConstant::TASK_INT_PRIORITY_HIGH;
	} else if(isEqualIgnoreCaseString(stringPriority,CommonConstant::TASK_STRING_PRIORITY_MEDIUM)){
		return CommonConstant::TASK_INT_PRIORITY_MEDIUM;
	} else if(isEqualIgnoreCaseString(stringPriority,CommonConstant::TASK_STRING_PRIORITY_LOW)){
		return CommonConstant::TASK_INT_PRIORITY_LOW;
	}
	return CommonConstant::TASK_INT_INVALID;
}

int FloatingTask::convertStringFinishedStatusToInt(string stringFinishedStatus){
	if(isEqualIgnoreCaseString(stringFinishedStatus,CommonConstant::TASK_STRING_STATUS_NOT_FINISHED)){
		return CommonConstant::TASK_INT_STATUS_NOT_FINISHED;
	} else if(isEqualIgnoreCaseString(stringFinishedStatus,CommonConstant::TASK_STRING_STATUS_FINISHED)){
		return CommonConstant::TASK_INT_STATUS_FINISHED;
	}
	return CommonConstant::TASK_INT_INVALID;
}

bool FloatingTask::isEqualIgnoreCaseString(string str1, string str2){
	str1 = toUpperCase(str1);
	str2 = toUpperCase(str2);

	if(str1 == str2){
		return true;
	}
	return false;
}

// interface methods
string FloatingTask::getStartTime(){ 
	return CommonConstant::EMPTY_STRING; 
}

string FloatingTask::getStartDate(){
	return CommonConstant::EMPTY_STRING; 
}

string FloatingTask::getEndTime(){
	return CommonConstant::EMPTY_STRING;
}

string FloatingTask::getEndDate(){ 
	return CommonConstant::EMPTY_STRING; 
}

string FloatingTask::getFullStartDateInfo(){
	return CommonConstant::EMPTY_STRING; 
}

string FloatingTask::getFullEndDateInfo(){
	return CommonConstant::EMPTY_STRING;
}

time_t FloatingTask::getStartTimeAndDate(){
	time_t dummy;
	time(&dummy);
	return dummy;
}

time_t FloatingTask::getEndTimeAndDate(){
	time_t dummy;
	time(&dummy);
	return dummy;
}

void FloatingTask::setStartTimeAndDate(time_t){
}

void FloatingTask::setStartTimeAndDate(struct tm){
}

void FloatingTask::setEndTimeAndDate(time_t){
}

void FloatingTask::setEndTimeAndDate(struct tm){
}

string FloatingTask::getTime(){	
	return CommonConstant::EMPTY_STRING; 
}

string FloatingTask::getDate(){	
	return CommonConstant::EMPTY_STRING; 
}

string FloatingTask::getFullDateInfo(){	
	return CommonConstant::EMPTY_STRING; 
}

time_t FloatingTask::getTimeAndDate(){
	time_t dummy;
	time(&dummy);
	return dummy;
}

struct tm FloatingTask::getTimeAndDateTmFormat(){
	struct tm dummy;
	dummy.tm_hour = CommonConstant::DEFAULT_TIME_HOURS;
	return dummy;
}

void FloatingTask::setTimeAndDate(time_t){
}

void FloatingTask::setTimeAndDate(struct tm){
}

FloatingTask::~FloatingTask(){
}